package cn.xiaolang.function.sql;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

public class DynSQLDemo {
	
	public static void main(String[] args) throws IOException {
		DynamicSQLHelper dSql = new DynamicSQLHelper();
		dSql.append("SELECT s.dept_name, s.id, s.name, t.year, t.semester, t.course_id, t.grade  ");
		dSql.append("  FROM student s   ");
		dSql.append("  LEFT JOIN takes t ON s.id = t.id ");
		dSql.append("  where s.id = '1' ");
		dSql.isNotEmpty(" and t.year = # ", "2015$")
				.isNotEmpty(" and t.month = # ", null)
				.isNull(" and t.name is null ", null)
				.isEqual(" and t.semester = $ ", 3, 3);

		System.out.println(dSql.getSql());
		System.out.println(dSql.getParams());
		System.out.println(dSql.getParams((DynamicSQLHelper.Parameter<String>) params -> params.get(0).toString()));
		System.out.println(dSql);

		System.out.println("+++++++++++++++++++++++++++++++++++++++++++");
		dSql.clear();
		String ids = "1,2,3,4,5";
		//dSql.append("delete from sdt_bdi_std_type ");
		//dSql.isNotEmpty("  where id in ($) ", ids);
		dSql.isNotEmpty(String.format("delete from %s where id in ($) ", "sdt_bdi_std_type"), ids);
		System.out.println(dSql);
		System.out.println(dSql.getParams());

	}
}